//
//  JGGamepad.h
//  JGInputDriver
//
//  Created by jagger.tu on 2025/3/21.
//

#import <Foundation/Foundation.h>
#import <JGVividEngine/JGVividEngine.h>

#ifndef JG_INVALID_INDEX
#define JG_INVALID_INDEX -1
#endif

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, JGGamepadType) {
    /// 物理手柄
    JGGamepadTypePhysical = 0,
    /// 虚拟手柄
    JGGamepadTypeVirtual = 1,
    /// 第三方手柄
    JGGamepadTypeThirdParty = 2
};

@class JGGamepad ;

@protocol JGGamepadDelegate <NSObject>

@optional

/// 手柄将发送事件,可以对事件做出额外的调整处理
/// - Parameters:
///   - gamepad: 手柄对象
///   - events: 手柄事件
- (void)gamepad:(JGGamepad *)gamepad willSendControlEvents:(NSArray<JGControlEvent *> *)events;

/// 手柄发送完成的事件
/// - Parameters:
///   - gamepad: 手柄对象
///   - events: 手柄事件
- (void)gamepad:(JGGamepad *)gamepad didSendControlEvents:(NSArray<JGControlEvent *> *)events;

/// 手柄被通知震动
/// - Parameters:
///   - gamepad: 手柄对象
///   - left: 左马达速度
///   - right: 右马达速度
- (void)gamepad:(JGGamepad *)gamepad shockWithLeft:(int)left right:(int)right;

@end

/// 基础手柄类
@interface JGGamepad : NSObject
/// 手柄产品名称,例如 `Xbox One`
@property (nonatomic, strong) NSString *productCategory;
/// 是无效的slotId
@property (nonatomic, assign, readonly) BOOL isInvalidSlotId;
/// 当前手柄名称
@property (nonatomic, strong) NSString *name;
/// 手柄插槽Id
@property (nonatomic, assign) NSInteger slotId;
/// 手柄本地Id
@property (nonatomic, assign) NSInteger deviceId;
/// 手柄类型
@property (nonatomic, assign) JGGamepadType type;
/// 手柄事件代理
@property (nonatomic, weak) id<JGGamepadDelegate> delegate;
/// 手柄证书
@property (nonatomic, strong) NSString *cert;
/// 加载完成回调
@property (nonatomic, strong, nullable) void(^complete)(NSInteger slotId, NSInteger deviceId);
/// 手柄证书更新
@property (nonatomic, strong, nullable) void(^upateCert)(JGGamepad *gamepad);
/// 手柄震动左右马达速度
- (void)shockWithLeft:(int)left right:(int)right;
/// 远程手柄参数,用于扫码手柄
- (NSDictionary *)remoteControllerParameters;

@end

NS_ASSUME_NONNULL_END
